home *** CD-ROM | disk | FTP | other *** search
/ Delphi Informant Complete 1995 - 2000 / Delphi Informant Complete 1995 to 2000.iso / Delphi Informant Magazine Complete Works SOURCE CODE 1998.rar / 1998 / Aug / DI9808AM / CommStatus.pas next >
Encoding:
Pascal/Delphi Source File  |  1998-05-05  |  1.2 KB  |  62 lines

  1. { This unit establishes a thread to monitor port status }
  2. unit CommStatus;
  3.  
  4. interface
  5.  
  6. uses
  7.   Windows, Classes, Graphics, ExtCtrls, TAPI;
  8.  
  9. type
  10.   TCommStatus = class(TThread)
  11.   private
  12.     { Private declarations }
  13.   protected
  14.     procedure Execute; override;
  15.   end;
  16.  
  17. implementation
  18.  
  19. uses
  20.   Tapiu_2;
  21.  
  22. const
  23.   off = 0;
  24.   red = 1;
  25.   yellow = 2;
  26.   green = 3;
  27.  
  28. { Important: Methods and properties of objects in VCL can only be used in a
  29.   method called using Synchronize, for example,
  30.  
  31.       Synchronize(UpdateCaption);
  32.  
  33.   and UpdateCaption could look like,
  34.  
  35.     procedure TCommStatus.UpdateCaption;
  36.     begin
  37.       Form1.Caption := 'Updated in a thread';
  38.     end; }
  39.  
  40. { TCommStatus }
  41.  
  42. procedure TCommStatus.Execute;
  43. var
  44.   dwEvent: DWord;
  45.   dwStatus: DWord;
  46. begin
  47.   dwEvent := 0;
  48.   SetCommMask(FPort, EV_DSR or EV_CTS or SETDTR);
  49.   repeat
  50.      WaitCommEvent(FPort, dwEvent, nil);
  51.      GetCommModemStatus(FPort, dwStatus);
  52.      case dwEvent of
  53.         EV_DSR: Form1.SetBitmap(Form1.DSR, green);
  54.         SETDTR: Form1.SetBitmap(Form1.DTR, green);
  55.         EV_CTS: Form1.SetBitmap(Form1.CTS, green);
  56.      end;
  57.      // Form1.SetBitmap(Form1.AA, green);
  58.   until Terminated;
  59. end;
  60.  
  61. end.
  62.